#include "Variable.h"
#include <iostream>
#include <cassert>
#include "Data.h"

using namespace std;

int Variable::s_nrOfInstances = 0;

Variable::Variable(const string& name, Data* initData) {
	assert(name != "");
	assert(initData);
	
	m_name = name;
	m_data = initData;
	m_type = initData->getType();
	
	s_nrOfInstances++;
}

Variable* Variable::createVariable(const string& name, Data* initData) {
	assert(name != "");
	assert(initData);
	
	Variable* newVariable = new Variable(name, initData);
	return newVariable;
}

Variable::~Variable() {
	s_nrOfInstances--;		
}

void Variable::setData(Data* data) {
	assert(data);
	assert(data->getType() == m_type);
	
	m_data = data;
}

Data* Variable::getCopyOfData() {
	assert(m_data);
	
	Data* newData = m_data->getCopy();
	return newData;
}

bool Variable::getBooleanValue() {
	assert(m_data->getType() == Data::BOOLEAN);
	
	return m_data->getBooleanValue();	
}

int Variable::getIntValue() {
	assert(m_data->getType() == Data::INT);
	
	return m_data->getIntValue();	
}

float Variable::getFloatValue() {
	assert(m_data->getType() == Data::FLOAT);
	
	return m_data->getFloatValue();	
}

string Variable::getStringValue() {
	assert(m_data->getType() == Data::STRING);
	return m_data->getStringValue();	
}

string Variable::getVariableName() {
	assert(m_data->getType() == Data::VARIABLE_NAME);
	return m_data->getVariableName();	
}

void Variable::setReferenced(bool value) {
	assert(m_data);
	
	DataHolder::setReferenced(value);
	m_data->setReferenced(value);
}








